package com.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.action.UserAction;
import com.bean.UserBean;
import com.exception.DBException;
import com.exception.UserException;
import com.util.HandleInfo;
import com.util.Regex;
import com.util.StateInfo;

public class UserDetailServlet extends HttpServlet
{

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		String userID = request.getParameter("userdetailid");
		if(null==userID)
		{
			HandleInfo.handle(request, response,  
					StateInfo.INNER_CONFIRM_FAIL);
			return;
		}
		if("".equals(userID))
		{
			HandleInfo.handle(request, response, StateInfo.INNER_CONFIRM_FAIL);
			return;
		}
		if(!Regex.checkUserID(userID))
		{
			HandleInfo.handle(request, response, StateInfo.INNER_CONFIRM_FAIL);
			return;
		}
		UserBean userBean = new UserBean();
		userBean.setUserID(userID);
		try
		{
			new UserAction().detailsUser(request, response, userBean);
		}
		catch (DBException e)
		{
			HandleInfo.handle(request, response, e.getMessage());
			return;
		}
		catch (UserException e)
		{
			HandleInfo.handle(request, response, e.getMessage());
			return;
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doGet(request, response);
	}

}
